package com.chezhujie.www.controller;


import com.chezhujie.www.constant.PageInfo;
import com.chezhujie.www.domain.Czjotherurl;
import com.chezhujie.www.service.CzjotherurlService;
import com.sys.core.page.Pagination;
import com.sys.user.base.controller.BaseController;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 
 * 
 * 创建人:cheny
 * 时间：2017年6月9日-下午4:02:45 
 * @version 1.0.0
 *
 */
@Controller
@RequestMapping("/other")
public class CzjotherurlController extends BaseController {
	private static final Logger log = LoggerFactory.getLogger(CzjotherurlController.class);
	public CzjotherurlController() {
	}
 

	@RequestMapping("svse")
	public void advertcount_svse(Czjotherurl czjotherurl,
			HttpServletRequest request, HttpServletResponse response,
			ModelMap model) throws Exception {
		
		try {
			czjotherurl.setCreatetime(new Date());
			czjotherurlService.svse(czjotherurl);
			jsonResult(1, "", "", "", response);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("error", e);
			jsonResult(0, "138", "监听第三方链接错误", "", response);
		}
		
	}
	
	@RequestMapping("list")
	public String advertcount_list(String beginTime, String endTime, Integer type,
			HttpServletRequest request, HttpServletResponse response,
			Integer pageSize,Integer pageNo,
			ModelMap model) throws Exception {
		
		try {
			   if (pageNo == null) {
		            pageNo = PageInfo.DEFAULT_PAGENO;
		        }
		        if (pageSize == null) {
		            pageSize = PageInfo.DEFAULT_PAGESIZE;
		        }
			Map<String, Object> map = new HashMap<String, Object>();
			
			if (StringUtils.isNotBlank(beginTime)) {
				map.put("beginTime", beginTime);
				map.put("createTime", 11);
				if (StringUtils.isBlank(endTime))
					map.put("endTime", new Date());
				else
					map.put("endTime", endTime);
			}

			if (!"".equals(type) && null != type) {
				map.put("type", type);
				model.addAttribute("type", type);
			} else {
				map.put("type", 0);
				model.addAttribute("type", 0);
			}

			Pagination pagination = czjotherurlService
					.listCzjotherurl(map,pageSize,pageNo);
			model.addAttribute("pagination", pagination);
			if (StringUtils.isNotBlank(beginTime)) {
				model.addAttribute("beginTime", beginTime);
			}
			if (StringUtils.isNotBlank(endTime)) {
				model.addAttribute("endTime", endTime);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "other/list";
	}
	
	@RequestMapping("detail")
	public String detail(String beginTime, String endTime, String url,
			HttpServletRequest request, HttpServletResponse response,
			Integer pageSize,Integer pageNo,Integer type,
			ModelMap model) throws Exception {
		
		try {
			  if (pageNo == null) {
		            pageNo = PageInfo.DEFAULT_PAGENO;
		        }
		        if (pageSize == null) {
		            pageSize = PageInfo.DEFAULT_PAGESIZE;
		        }
		        Map<String, Object> map = new HashMap<String, Object>();
		    	if (StringUtils.isNotBlank(beginTime)) {
					map.put("beginTime", beginTime);
					map.put("createTime", 11);
					if (StringUtils.isBlank(endTime))
						map.put("endTime", new Date());
					else
						map.put("endTime", endTime);
				}

				if (!"".equals(type) && null != type) {
					map.put("type", type);
					model.addAttribute("type", type);
				} else {
					map.put("type", 0);
					model.addAttribute("type", 0);
				}
			
			map.put("type", type);
			Pagination pagination = czjotherurlService
					.getOtherDetailByType(map,pageSize,pageNo);
			model.addAttribute("pagination", pagination);

			if (StringUtils.isNotBlank(beginTime)) {
				model.addAttribute("beginTime", beginTime);
			}
			if (StringUtils.isNotBlank(endTime)) {
				model.addAttribute("endTime", endTime);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return "other/detail";
	}
	
	
	@Autowired
	private CzjotherurlService czjotherurlService;

}